﻿using server.Core.Command;
using server.Model;
using server.Tool;
using SuperSocket.SocketBase.Command;
using SuperSocket.SocketBase.Protocol;

namespace server.command
{
    /// <summary>
    /// 心跳
    /// </summary>
   public class HeartBeat : CommandBase<PubgSession, StringRequestInfo>
    {
        public override void ExecuteCommand(PubgSession session, StringRequestInfo requestInfo)
        {
            SessionItem sessionItem = null;
            PubgSession.mOnLineConnections.TryGetValue(session, out sessionItem);
            GPSUserItem gpsItem = Utils.CollectionsConvert.ToObject<GPSUserItem>(requestInfo.Body.ToString());
            if (sessionItem!=null && gpsItem!=null)
            {
                sessionItem.heartTimeStamp = TimeUtils.GetCurrentTimestamp();
                sessionItem.gpsItem.userId  = gpsItem.userId;
                sessionItem.gpsItem.userName = gpsItem.userName;
                sessionItem.gpsItem.userType = gpsItem.userType;
                if(gpsItem.userId==-1)
                {
                    sessionItem.isLogin = false;
                }
                else
                {
                    sessionItem.isLogin = true;
                }
                    //回送心跳包
                    string data = CommandName.HeartBeat + Constant.START_SPLIT + "hello" + "\r\n";
                session.Send(data);
               
            }

        }
    }
}
